﻿using System.Web.Mvc;
using System.Web.Mvc.Html;
using System;
using System.Linq.Expressions;
using Microsoft.Security.Application;
using System.Text.RegularExpressions;
namespace ASPItalia.ModelVirtualCasting.Web.Utils
{
    public static class HtmlExtensions
    {
		/// <summary>
		/// Crea link con un'immagine all'interno.
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="imageUrl"></param>
		/// <param name="alternateText"></param>
		/// <param name="actionName"></param>
		/// <param name="controllerName"></param>
		/// <param name="routeValues"></param>
		/// <returns></returns>
        public static string ImageActionLink(this HtmlHelper helper, string imageUrl, string alternateText, string actionName, string controllerName, object routeValues)
        { 
            var tagBuilder = new TagBuilder("img");
            tagBuilder.MergeAttribute("src", imageUrl);
            tagBuilder.MergeAttribute("alt", alternateText);
            string text = tagBuilder.ToString();

			return helper.ActionLink("REPLACE.THIS.PLACEHOLDER", actionName, controllerName, routeValues, null).ToString().Replace("REPLACE.THIS.PLACEHOLDER", tagBuilder.ToString());
        }
		
		/// <summary>
		/// Crea link con un'immagine all'interno.
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="imageUrl"></param>
		/// <param name="alternateText"></param>
		/// <param name="actionName"></param>
		/// <param name="routeValues"></param>
		/// <returns></returns>
        public static string ImageActionLink(this HtmlHelper helper, string imageUrl, string alternateText, string actionName, object routeValues)
        {
            return ImageActionLink(helper, imageUrl, alternateText, actionName, null, routeValues);
        }
		
		/// <summary>
		/// Rimuove l'HTML dal testo.
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		public static string RemoveHtml(this string text)
		{
			if (!string.IsNullOrEmpty(text))
				return Regex.Replace(text, "<[^>]*>", String.Empty);

			return text;
		}
    }
}